package top.kaoshanji.r5ch12d;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 代码清单-r5ch12d-01：验证一下启动独立线程调用事务方法
 * @author kaoshanji
 * ^_^
 * create time 2025/5/11 10:27
 */
public class UserServiceContext {

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("r5ch12d/application-context.xml");

        UserService userService = (UserService)context.getBean("userService");
        JdbcTemplate jdbcTemplate = (JdbcTemplate)context.getBean("jdbcTemplate");

        //插入一条记录，初始分数为10
        jdbcTemplate.execute(" INSERT INTO t_user1(user_name,password,score,last_logon_time) VALUES('tom','123456',10," + System.currentTimeMillis() + ") ");


        System.out.println("...在运行userService#logon方法之前...");
        userService.logon("tom");
        System.out.println("...在运行userService#logon方法之后...");

        jdbcTemplate.execute(" DELETE FROM t_user1 WHERE user_name='tom' ");

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}


